<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<script type="text/javascript">
	var $dg_userrole ;
	$(function() {
		$dg_userrole = $("#dg_userrole").datagrid({
			url: base.contextPath+"/sysmgr/userrole/doNotNeedAuth_datagrid.do",
			idField: 'id', fit: true, border: false, pageSize: 30, pageList: [30,40,50,100,200],
			striped:true, pagination: true, singleSelect: false,
			frozenColumns: [[
			    { field: 'ck', checkbox: true },
			    { field: 'id', title: 'ID', width: 80, hidden: true }
			]],
			columns: [[
			    { field: 'name', title: '组名称', width: 100, sortable: true },
			    { field: 'remark', title: '组描述', width: 100, sortable: true }, 
			    { field: 'created', title: '创建时间', width: 140, sortable: true },
			    { field: 'modifyDate', title: '最后修改时间', width: 140, sortable: true }
			]],
	        onLoadSuccess: function(row, data) {
	        	 $.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
	        	 var group_ids = "${permit.group_ids}" ;
	        	 if(group_ids.length > 0) {
		        	 $.each(group_ids.split(","), function(i, p) {
			        	 $dg_userrole.datagrid("selectRecord", p) ;
		        	 });
	        	 }
	         }
		}) ;
		
	});
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		var ids = [];
		var rows = $dg_userrole.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		}
		var id = "${permit.id}" ;
		$.easyui.loading({ msg: "数据添加中，请稍等..."});
		$.post(base.contextPath+"/sysmgr/permits/doNotNeedAuth_addUserRole.do", {id: id, userrole_ids: ids.join(',')}, function(result) {
			if (result.status) {
				alertify.success(result.msg);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();warning.success(result.msg);
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	
</script>
<div id="dg_userrole"></div>
